package edu.ucsd.ccdb.cytoSegPopup;

import java.io.IOException;
import java.net.URL;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.xml.sax.SAXException;

public class CytosegService {
	
//	"training1=/CCDBProdZone/home/CCDB_DATA_USER/acquisition/project_10143/microscopy_2490/b" +
//	"&training2=/CCDBProdZone/home/CCDB_DATA_USER/acquisition/project_10143/microscopy_2490/a" +
//	"&input=/CCDBProdZone/home/CCDB_DATA_USER/acquisition/project_10143/microscopy_2490/a_membranes" +
//	"&output=/CCDBProdZone/home/CCDB_DATA_USER/acquisition/project_10143/microscopy_2490" +
//	"&training1Name=b" +
//	"&training2Name=a" +
//	"&inputName=a_membranes"
	
	public static void getExecutionSegtoseg (String training1, String training2, String input, String output ) throws IOException, SAXException, ParserConfigurationException {
		
		String cytosegURL = CytosegConfiguration.URL + "?training1=" + training1 + "&training2=" + training2 + 
						"&input=" + input + "&output=" + output +
						"&training1Name=" + getNameOnly(training1) + 
						"&training2Name=" + getNameOnly(training2) + 
						"&inputName=" + getNameOnly(input);
		
		URL url = new URL(cytosegURL);

		DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
		Document doc = docBuilder.parse(url.openStream());
		
		// waiting :)
	}
	
	private static String getNameOnly (String data ) {
		if (data == null && data == "")
			return data;
		
		int index = data.lastIndexOf('/');
		
		return data.substring(index + 1);
	}
}
